import java.util.Arrays;

public class Solution {
    public ListNode partition(ListNode head, int x) {
        if(head == null || head.next ==null){
            return head;
        }
        ListNode dummy1 = new ListNode(-101);
        ListNode dummy2 = new ListNode(-101);
        ListNode cur1 = dummy1;
        ListNode cur2 = dummy2;

        while(head != null){
            if(head.val < x){
                cur1.next = head;
                cur1 = cur1.next;
            } else {
                cur2.next = head;
                cur2 = cur2.next;
            }
            head = head.next;
        }
        cur2.next = null;
        cur1.next = dummy2.next;

        return dummy1.next;

    }
}

class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}
